package com.dycx.api.controller.manage.user;

import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.user.dto.IndustryTypeDTO;
import com.dycx.user.service.IndustryTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping(value = "/manage/user/industryType")
public class IndustryTypeController {

    @Resource
    private IndustryTypeService industryTypeService;

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.USER_INDUSTRY_TYPE, bizValue = "{#industryTypeDto.id}")
    @PostMapping("/add")
    public RestResponse<?> add(@RequestBody @Valid IndustryTypeDTO industryTypeDto) {
        return industryTypeService.add(industryTypeDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.USER_INDUSTRY_TYPE, bizValue = "{#industryTypeDto.id}")
    @PostMapping("/edit")
    public RestResponse<?> edit(@RequestBody @Valid IndustryTypeDTO industryTypeDto) {
        return industryTypeService.edit(industryTypeDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.USER_INDUSTRY_TYPE, bizValue = "{#typeId}")
    @GetMapping("/delete")
    public RestResponse<?> delete(int typeId) {
        return industryTypeService.delete(typeId) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 查询 根据主键 id 查询
     **/
    @GetMapping("/getAllList")
    public RestResponse<?> getAllList() {
        return RestResponse.success(industryTypeService.getAllList(0));
    }

    /**
     * 修改排序
     **/
    @WriterLog(bizType = BizTypeEnum.USER_INDUSTRY_TYPE, bizValue = "{#industryTypeDTO.id}")
    @PostMapping("/updateSort")
    public RestResponse<?> updateSort(@RequestBody IndustryTypeDTO industryTypeDTO) {
        return RestResponse.success(industryTypeService.updateSort(industryTypeDTO));
    }

    /**
     * 修改状态
     **/
    @WriterLog(bizType = BizTypeEnum.USER_INDUSTRY_TYPE, bizValue = "{#industryTypeDTO.id}")
    @PostMapping("/updateStatus")
    public RestResponse<?> updateStatus(@RequestBody IndustryTypeDTO industryTypeDTO) {
        return RestResponse.success(industryTypeService.updateStatus(industryTypeDTO));
    }

    /**
     * 查询子类
     **/
    @GetMapping("/getListByParentId")
    public RestResponse<?> getListByParentId(Integer parentId) {
        return RestResponse.success(industryTypeService.getListByParentId(parentId));
    }
}
